<template>
    <div class="commodity">
        <div class="query_tool">
            <div class="item">
                <span class="lable">商品名称</span>
                <div class="value">
                    <el-input v-model="queryValue.name" placeholder="请输入商品名称" clearable />
                </div>
            </div>
            <el-button @click="queryList" type="primary" size="medium">查询</el-button>
            <el-button @click="openDialog" type="warning" size="medium">新增</el-button>
        </div>
        <div class="content">
            <el-table :data="tableData" style="width: 100%">
                <el-table-column prop="id" label="ID" width="180"> </el-table-column>
                <el-table-column prop="name" label="商品名称"></el-table-column>
                <el-table-column prop="unitPrice" label="商品单价" width="100"></el-table-column>
                <el-table-column prop="surplus" label="剩余数量" width="100"></el-table-column>
                <el-table-column prop="remarks" label="备注" width="100"></el-table-column>
                <el-table-column fixed="right" label="操作" width="100">
                    <template v-slot="scope">
                        <el-button @click="edit(scope.row)" type="text">编辑</el-button>
                        <el-divider direction="vertical"></el-divider>
                        <delButton @del="dele(scope.row)"></delButton>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination
                    :hide-on-single-page="true"
                    background
                    layout="prev, pager, next"
                    v-model:currentPage="page.current"
                    @currentChange="getList"
                    :total="page.total">
            </el-pagination>
        </div>
        <Dialog ref="dialogDom" :title="dialogTitle" @ok="getList"></Dialog>
    </div>
</template>

<script>
import Dialog from './Dialog.vue'
import { queryValue, tableData, getList, dele, page, queryList } from './setupTable.js'
import { setupDialog } from './setupDialog.js'
import delButton from '../../components/del-button.vue'
export default {
    name: 'Commodity',
    components: {
        Dialog,delButton
    },
    setup() {
        const dialogData = setupDialog('新增商品', '编辑商品')
        return {
            queryValue,
            tableData,
            getList,
            queryList,
            dele,
            page,
            ...dialogData
        }
    },
    methods: {
        // openDialog () {
        //     console.log(this.$refs);
        //     console.log(this.$refs.dialogDom);
        //     this.$refs.dialogDom.open()
        // }
    }
}
</script>

<style lang="less" scoped>
@import "../../assets/css/queryTool.less";

</style>
